/*
 *   Copyright (C) 2006-2007 Jiri Majer. All Rights Reserved.
 *   DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 *   This code is free software; you can redistribute it and/or modify it
 *   under the terms of the GNU General Public License version 2 only, as
 *   published by the Free Software Foundation.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the Free Software
 *   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

package org.diabetesdiary.calendar.ui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JPanel;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import org.openide.util.NbBundle;

public final class NewPatientVisualPanel1 extends JPanel {
    
    class MyDocumentListener implements DocumentListener {
        
        public void insertUpdate(DocumentEvent e) {
            NewPatientVisualPanel1.this.wizard.fireChangeEvent();
        }
        public void removeUpdate(DocumentEvent e) {
            NewPatientVisualPanel1.this.wizard.fireChangeEvent();
        }
        public void changedUpdate(DocumentEvent e) {
            //Plain text components don't fire these events
        }
    }
    
    private NewPatientWizardPanel1 wizard;
    
    /** Creates new form NewPatientVisualPanel1 */
    public NewPatientVisualPanel1(NewPatientWizardPanel1 wizard) {
        this.wizard = wizard;
        initComponents();
        jLabel6.setVisible(false);
        email.setVisible(false);
        
        buttonGroup1.add(pump);
        buttonGroup1.add(injection);
        sex.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                NewPatientVisualPanel1.this.wizard.fireChangeEvent();
            }
        });
        email.getDocument().addDocumentListener(new MyDocumentListener());
        name.getDocument().addDocumentListener(new MyDocumentListener());
        surname.getDocument().addDocumentListener(new MyDocumentListener());
        textDatum.getDocument().addDocumentListener(new MyDocumentListener());
    }
    
    private ComboBoxModel createSexModel(){
        DefaultComboBoxModel model = new DefaultComboBoxModel(new String[]{NbBundle.getMessage(NewPatientVisualPanel1.class,"Male"),NbBundle.getMessage(NewPatientVisualPanel1.class,"Female")});
        return model;
    }
    
    public void setPatientEdit(boolean edit){
        pump.setEnabled(!edit);
        injection.setEnabled(!edit);
    }
    
    @Override
    public String getName() {
        return NbBundle.getMessage(NewPatientVisualPanel1.class,"newpatienttitle");
    }
    
    public String getPatientName(){
        return name.getText();
    }
    
    public String getSurname(){
        return surname.getText();
    }
    
    public String getDateBorn(){
        return textDatum.getText();
    }
    
    public boolean isMale(){
        return sex.getSelectedIndex() == 0;
    }
    
    public String getEmail(){
        return email.getText();
    }
    
    public void setEmail(String emailS){
        email.setText(emailS);
    }
    
    public boolean isPumpUsage(){
        return pump.isSelected();
    }
    
    public void setPumpUsage(boolean usage){
        pump.setSelected(usage);
        injection.setSelected(!usage);
    }
    
    public void setPatientName(String patName){
        name.setText(patName);
    }
    
    public void setDateBorn(String born){
        textDatum.setText(born);
    }
    
    public void setSurname(String patSurname){
        surname.setText(patSurname);
    }
    
    public void setSex(boolean male){
        if(male){
            sex.setSelectedIndex(0);
        }else{
            sex.setSelectedIndex(1);
        }
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        name = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        surname = new javax.swing.JTextField();
        sex = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        textDatum = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        email = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        injection = new javax.swing.JRadioButton();
        pump = new javax.swing.JRadioButton();

        org.openide.awt.Mnemonics.setLocalizedText(jLabel1, NbBundle.getMessage(NewPatientVisualPanel1.class,"name")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(jLabel2, NbBundle.getMessage(NewPatientVisualPanel1.class,"surname")); // NOI18N

        sex.setModel(createSexModel());

        org.openide.awt.Mnemonics.setLocalizedText(jLabel4, NbBundle.getMessage(NewPatientVisualPanel1.class,"gender")); // NOI18N

        textDatum.setColumns(10);
        textDatum.setText(NbBundle.getMessage(NewPatientVisualPanel1.class, "NewRecord_DatePattern")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(jLabel5, NbBundle.getMessage(NewPatientVisualPanel1.class,"dateofbirth")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(jLabel6, NbBundle.getMessage(NewPatientVisualPanel1.class,"email")); // NOI18N

        injection.setSelected(true);
        org.openide.awt.Mnemonics.setLocalizedText(injection, NbBundle.getMessage(NewPatientVisualPanel1.class,"inspen")); // NOI18N
        injection.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        injection.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                injectionActionPerformed(evt);
            }
        });

        org.openide.awt.Mnemonics.setLocalizedText(pump, NbBundle.getMessage(NewPatientVisualPanel1.class,"inspump")); // NOI18N
        pump.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
        pump.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pumpActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabel1)
                    .add(jLabel2)
                    .add(jLabel4)
                    .add(jLabel5)
                    .add(jLabel6))
                .add(12, 12, 12)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(injection)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(pump))
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                        .add(textDatum, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(sex, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .add(surname)
                        .add(name, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 188, Short.MAX_VALUE)
                        .add(email)))
                .addContainerGap(149, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(name, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel1))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(surname, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel2))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(sex, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel4))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(textDatum, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel5))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(jLabel6)
                    .add(email, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(injection)
                    .add(pump))
                .addContainerGap(142, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents
    
    private void pumpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pumpActionPerformed
        NewPatientVisualPanel1.this.wizard.fireChangeEvent();
    }//GEN-LAST:event_pumpActionPerformed
    
    private void injectionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_injectionActionPerformed
        NewPatientVisualPanel1.this.wizard.fireChangeEvent();
    }//GEN-LAST:event_injectionActionPerformed
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JTextField email;
    private javax.swing.JRadioButton injection;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JTextField name;
    private javax.swing.JRadioButton pump;
    private javax.swing.JComboBox sex;
    private javax.swing.JTextField surname;
    private javax.swing.JTextField textDatum;
    // End of variables declaration//GEN-END:variables
    
}

